﻿using MediatR;
using SystemWFH.API.Application.Command.EquipmentCommand;
using SystemWFH.Domain;
using SystemWFH.Infrstructer.Interface;

namespace SystemWFH.API.Application.CommandHandlers.EquipmentCommandHandler
{
    public class EquipmentAddCommandHandler : IRequestHandler<EquipmentAddCommand, int>
    {
        /// <summary>
        /// 服务
        /// </summary>
        private readonly IEquipmentRepository equipmentRepository;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="equipmentRepository">服务</param>
        public EquipmentAddCommandHandler(IEquipmentRepository equipmentRepository)
        {
            this.equipmentRepository = equipmentRepository;
        }
        /// <summary>
        /// 设备添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Handle(EquipmentAddCommand request, CancellationToken cancellationToken)
        {
            var shijian = request.equipmentProcurementData.Value.ToUniversalTime();
            var shijian1= request.equipmentAddData.ToUniversalTime();
            return await equipmentRepository.AddedAsync(new Equipment
            {
                equipmentId = request.equipmentId,
                equipmentName = request.equipmentName,
                equipmentType = request.equipmentType,
                equipmentAddData = shijian1,
                equipmentAddPeople = request.equipmentAddPeople,
                equipmentImage = request.equipmentImage,
                equipmentNumbering = request.equipmentNumbering,
                equipmentProcurementData = shijian,
                equipmentProductionLine = request.equipmentProductionLine,
                equipmentSerialNumber = request.equipmentSerialNumber,
                equipmentState = request.equipmentState,
                AddName = "李四",
                AddTime = DateTime.Now.ToUniversalTime(),
            });
        }
    }
}
